import torch
import os

class SharedData:
    def __init__(self):
        # 模型相关配置
        self.model_config = {
            "version": "YOLOv8",
            "weight_path": "",
            "confidence": 0.5,
            "iou": 0.5,
            "device": "GPU" if torch.cuda.is_available() else "CPU",
            "image_size": 640,
            "project": "runs/detect",
            "show": True,
            "save_frames": False,
            "save_txt": False,
            "save_conf": False,
            "save_crop": False,
            "show_labels": True,
            "show_conf": True,
            "show_boxes": True
        }

        # 预训练模型库
        self.pretrained_models = {
            "YOLOv8": ["yolov8n.pt", "yolov8s.pt", "yolov8m.pt", "yolov8l.pt", "yolov8x.pt"],
            "YOLOv7": ["yolov7.pt", "yolov7x.pt", "yolov7-w6.pt"],
            "YOLOv6": ["yolov6n.pt", "yolov6s.pt", "yolov6m.pt", "yolov6l.pt"],
            "YOLOv5": ["yolov5n.pt", "yolov5s.pt", "yolov5m.pt", "yolov5l.pt", "yolov5x.pt"],
            "YOLOv9": ["yolov9c.pt", "yolov9e.pt"]
        }

        # 最近文件功能
        self.recent_files = []
        self.recent_file_path = "recent_files.json"

        # 界面元素引用
        self.ui_elements = {
            "app": None,
            "file_listbox": None,
            "pred_listbox": None,
            "source_canvas": None,
            "result_canvas": None,
            "version_combobox": None,
            "weight_combobox": None,
            "confidence_scale": None,
            "confidence_label": None,
            "iou_scale": None,
            "iou_label": None
        }

        # 媒体相关
        self.image_paths = []  # 图片路径列表
        self.video_paths = []  # ✅ 新增：视频路径列表
        self.current_image_index = -1
        self.current_video_index = -1 # ✅ 新增：视频索引
        self.pred_file_paths = []
        self.current_pred_index = -1
        self.cap = None
        self.video_playing = False
        self.current_source = ""        # 标志预测文件的类型 - camera、picture、video
        self.infer_paused = False       # 标志模型预测的状态 - 是否暂停
